package demo.practice.leetcode;

public class P316 {

    public static void main(String[] args) {

        P316 p316= new P316();
        p316.removeDuplicateLetters("bcabc");
    }

    public String removeDuplicateLetters(String s) {

        int [] arr= new int[26];
        for(int i=0;i<s.length();i++){
            arr[s.charAt(i)-'a']=1;
        }

        StringBuffer sb= new StringBuffer();
        for(int j=0;j<arr.length;j++){
           if(arr[j]>0)
               sb.append((char)(j+'a'));
           if(sb.length()>s.length())
               break;
        }
        return sb.toString();
    }
}
